package com.ruoyi.web.controller.basic;

import com.github.pagehelper.PageInfo;
import com.ruoyi.basic.domain.Course;
import com.ruoyi.system.domain.Result;

import com.ruoyi.basic.service.CourseService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("basic/course")
public class CourseController {
    @Autowired
    private CourseService courseService;
    /**
     * 查课程列表
     */
    @GetMapping("list")
    public Result find(@Param("pageNum") Integer pageNum, @Param("pageSize")Integer pageSize,@Param("classCode")Integer classCode,@Param("name")String name,@Param("tno")String tno,@Param("tname")String tname){
        Result result = new Result();
        PageInfo pageInfo = courseService.find(pageNum,pageSize,classCode,name,tno,tname);
        result.setState(200);
        result.setMessage("获取成功");
        result.setData(pageInfo);
        return result;
    }

    /**
     * 查班级列表
     */
    @GetMapping("studentList")
    public Result findStudent(@Param("pageNum") Integer classCode){
        Result result = new Result();
        PageInfo pageInfo = courseService.findStudent(classCode);
        result.setState(200);
        result.setMessage("获取成功");
        result.setData(pageInfo);
        return result;
    }

    /**
     * 查所有人员列表
     */
    @GetMapping("allUserList")
    public Result findAllStudent(@Param("roleId") Integer roleId){
        Result result = new Result();
        PageInfo pageInfo = courseService.findAllStudent(roleId);
        result.setState(200);
        result.setMessage("获取成功");
        result.setData(pageInfo);
        return result;
    }

    /**
     * 更新课程信息
     */
    @PutMapping
    public Result updataCourse(@Validated @RequestBody Course course){
        Result result = new Result();
        PageInfo pageInfo = courseService.updataCourse(course);
        result.setState(200);
        result.setMessage("修改成功");
        result.setData(pageInfo);
        return result;
    }

    /**
     * 查部门列表
     */
    @GetMapping("dept")
    public Result findDept(){
        Result result = new Result();
//        PageInfo pageInfo = courseService.findDept();
        result.setState(200);
        result.setMessage("获取成功");
        result.setData(courseService.findDept());
        return result;
    }
}
